package com.example.controller.medical;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.common.Result;

import com.example.model.dto.OfficeDto;
import com.example.model.entity.medical.Office;
import com.example.model.vo.OfficeVO;
import com.example.service.medical.OfficeService;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * 科室表前端操作接口
 **/
@RestController
@RequestMapping("/office")
@Api(tags = "科室接口")
public class OfficeController {

    @Resource
    private OfficeService officeService;



    /**
     * 查询挂号量靠前的科室
     * @return
     */
    @ApiOperation(value = "查询挂号量靠前的科室")
    @GetMapping("/selectTopOffice")
    public Result getTopOffices() {
        List<OfficeVO> list = officeService.selectTopOffice();
        return Result.success(list);
    }

    /**
     * 根据信息查询科室
     * @param officeDto 科室信息
     * @return
     */
    @ApiOperation(value = "根据信息查询科室")
    @PostMapping("/selectOfficePage")
    public Result selectOfficePage(@RequestBody OfficeDto officeDto) {
        PageInfo<OfficeVO> officePage = officeService.selectByInfoPage(officeDto);
        return Result.success(officePage);
    }
    /**
     * 新增
     */
    @ApiOperation(value = "新增科室")
    @PostMapping("/add")
    public Result add(@RequestBody Office Office) {
        officeService.add(Office);
        return Result.success();
    }

    /**
     * 删除
     */
    @ApiOperation(value = "删除科室")
    @DeleteMapping("/delete/{id}")
    public Result deleteById(@PathVariable Integer id) {
        officeService.deleteById(id);
        return Result.success();
    }

    /**
     * 批量删除
     */
    @ApiOperation(value = "批量删除科室")
    @DeleteMapping("/delete/batch")
    public Result deleteBatch(@RequestBody List<Integer> ids) {
        officeService.deleteBatch(ids);
        return Result.success();
    }

    /**
     * 修改
     */
    @ApiOperation(value = "修改科室")
    @PutMapping("/update")
    public Result updateById(@RequestBody Office Office) {
        officeService.updateById(Office);
        return Result.success();
    }

    /**
     * 根据ID查询
     */
    @ApiOperation(value = "根据ID查询科室")
    @GetMapping("/selectById/{id}")
    public Result selectById(@PathVariable Integer id) {
        Office Office = officeService.selectById(id);
        return Result.success(Office);
    }

    /**
     * 查询所有
     */
    @ApiOperation(value = "查询所有科室")
    @GetMapping("/selectAll")
    public Result selectAll(Office office) {
        List<OfficeVO> list = officeService.selectAll(office);
        return Result.success(list);
    }

    /**
     * 分页查询
     */
    @ApiOperation(value = "分页查询科室")
    @GetMapping("/selectPage")
    public Result selectPage(Office Office,
                             @RequestParam(defaultValue = "1") Integer pageNum,
                             @RequestParam(defaultValue = "10") Integer pageSize) {
        PageInfo<OfficeVO> page = officeService.selectPage(Office, pageNum, pageSize);
        return Result.success(page);
    }

}
